package com.herench.bs.handler;


import com.herench.bs.agent.IInHosAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Map;


/**
 * Created by liuxiaohui on 2019/3/26.
 */
@Component
@Handler(code = "200109",name="开具电子住院证：CreateInpNotice()")
public class CreatInpNoticeHandler extends AbstractMessageHandler {

    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());

        // **************** 微信前端传入的参数 ******************************************* Start
        // 系统编码：微信前端区分医院用
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");

        // 身份证号
        String idNo = requestMessage.getArgsPropertyStringValue("idNo");
        //Assert.notNull(idNo, "idNo 不可为空！");
        // 患者ID
        String patientId = requestMessage.getArgsPropertyStringValue("patientId");
        // 入院次数
        String visitId = requestMessage.getArgsPropertyStringValue("visitId");
        // 住院周数
        String week = requestMessage.getArgsPropertyStringValue("week");
        // 是否使用药品
        String drugUser = requestMessage.getArgsPropertyStringValue("drugUser");
        // 手术种类
        String operation = requestMessage.getArgsPropertyStringValue("operation");
        // 预交金金额
        String prepayment = requestMessage.getArgsPropertyStringValue("prepayment");
        // 开证时间
        String enterDate = requestMessage.getArgsPropertyStringValue("enterDate");
        // 工作单位
        String serviceAgency = requestMessage.getArgsPropertyStringValue("serviceAgency");
        // 入院病情
        String patAdmCondition = requestMessage.getArgsPropertyStringValue("patAdmCondition");
        // 开证医生工号
        String noticeDoctorEmp = requestMessage.getArgsPropertyStringValue("noticeDoctorEmp");
        //Assert.notNull(noticeDoctorEmp, "noticeDoctorEmp 不可为空！");
        // 有效日期
        String validityDate = requestMessage.getArgsPropertyStringValue("validityDate");
        // 入院科室编码
        String inDept = requestMessage.getArgsPropertyStringValue("inDept");
        // 门诊诊断
        String clinicDiagnosis = requestMessage.getArgsPropertyStringValue("clinicDiagnosis");
        // 联系电话
        String phoneNumber = requestMessage.getArgsPropertyStringValue("phoneNumber");
        // 现住
        String currentAddr = requestMessage.getArgsPropertyStringValue("currentAddr");
        // 是否急诊
        String isJz = requestMessage.getArgsPropertyStringValue("isJz");


        // **************** 微信前端传入的参数 ******************************************* End

        // 医院代码：微信后端区分医院用
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);

        // 获取Bean信息
        IInHosAgent inHosAgent = getCleverClinicContext().getApplicationContext().getBean(IInHosAgent.class);
        // 设定入参：微信
        Map<String, Object> res = inHosAgent.createInpNotice(channelCode, hospitalCode, idNo, patientId, visitId, week, drugUser, operation, prepayment, enterDate, serviceAgency, patAdmCondition, noticeDoctorEmp, validityDate, inDept, clinicDiagnosis, phoneNumber, currentAddr, isJz);

        // 设置应答信息：HIS前置
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage, res);

        return responseMessage;
    }
}
